#!/usr/bin/env python3
"""
示例代码：展示如何使用Node和Graph类
"""

from graph_classes import Node, Graph


def main():
    # 创建一个图
    graph = Graph()
    
    # 创建一些示例节点
    node1 = Node(
        id=0,
        op="ALLOC",
        buf_id=0,
        size=256,
        type="L0C"
    )
    
    node2 = Node(
        id=1,
        op="ALLOC", 
        buf_id=1,
        size=128,
        type="L1"
    )
    
    node3 = Node(
        id=3,
        op="COPY_IN",
        pipe="MTE2",
        cycles=325,
        bufs=[1]
    )
    
    # 添加节点到图中
    graph.add_node(node1)
    graph.add_node(node2)
    graph.add_node(node3)
    
    # 添加边
    graph.add_edge(0, 1)  # 从节点0到节点1
    graph.add_edge(1, 3)  # 从节点1到节点3
    
    # 打印图的信息
    print(f"图的信息: {graph}")
    print(f"节点数量: {len(graph)}")
    
    # 查询节点信息
    print("\n节点信息:")
    for node_id in [0, 1, 3]:
        node = graph.get_node(node_id)
        if node:
            print(f"  {node}")
            print(f"    后继节点: {graph.get_successors(node_id)}")
            print(f"    前驱节点: {graph.get_predecessors(node_id)}")
    
    # 展示节点的详细属性
    print(f"\n节点3的详细信息:")
    node = graph.get_node(3)
    if node:
        print(f"  ID: {node.id}")
        print(f"  操作: {node.op}")
        print(f"  管道: {node.pipe}")
        print(f"  周期: {node.cycles}")
        print(f"  缓冲区: {node.bufs}")


if __name__ == "__main__":
    main()
